package com.uek.service.Impl;

import com.uek.mapper.BackgroundUserMapper;
import com.uek.pojo.BackgroundUser;
import com.uek.pojo.BackgroundUserExample;
import com.uek.service.BackUserService;
import com.uek.utilspojo.BackUserUtil;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class BackUserServiceImpl implements BackUserService {
    @Autowired
    BackgroundUserMapper backgroundUserMapper;
    @Override
    public Result userLogin(String uname,String pw) {
        BackgroundUserExample backgroundUserExample = new BackgroundUserExample();
        BackgroundUserExample.Criteria criteria = backgroundUserExample.createCriteria();
        criteria.andPasswordEqualTo(pw);
        criteria.andUsernameEqualTo(uname);
        List<BackgroundUser> backgroundUsers = backgroundUserMapper.selectByExample(backgroundUserExample);
        if (backgroundUsers.isEmpty()){
            return Result.failure(ApiCode.ERROR.getCode(), "用户名和密码错误");
        }else {
            BackUserUtil backUserUtil = new BackUserUtil();
            backUserUtil.setId(backgroundUsers.get(0).getId());
            backUserUtil.setUsername(backgroundUsers.get(0).getUsername());
            backUserUtil.setName(backgroundUsers.get(0).getName());
            backUserUtil.setToken("111111111111111");
            Result result = ResultData.success(ApiCode.SUCCESS.getCode(), "认证成功");
            return result;

        }
    }
}
